package header

// VolumeKey for Volume header
var VolumeKey = []string{
	"Identification",
	"SiteInfo",
	"HardwareConf",
	"ProcessorConf",
	"DataProcess",
	"DataStorge",
	"Diagnostics",
}

// SubHeader for Volume header
var SubHeader = map[string]([]string){
	VolumeKey[0]: idenKey,
	VolumeKey[1]: siteInfoKey,
	VolumeKey[2]: hardwareConfKey,
	VolumeKey[3]: processorConfKey,
	VolumeKey[4]: dataProcessingKey,
	VolumeKey[5]: dataStorgeKey,
	VolumeKey[6]: diagnosticsKey,
}

// InitVolumeHeader inits Volume header
func InitVolumeHeader() map[string](map[string][]byte) {
	return map[string](map[string][]byte){
		VolumeKey[0]: initIden(),
		VolumeKey[1]: initSiteInfo(),
		VolumeKey[2]: initHardwareConf(),
		VolumeKey[3]: initProcessorConf(),
		VolumeKey[4]: initDataProcessing(),
		VolumeKey[5]: initDataStorge(),
		VolumeKey[6]: initDiagnostics(),
	}
}

// idenKey for identification header
var idenKey = []string{
	"MagicNum",
	"ByteOrdering",
	"VersionNum",
	"ModeOfOperation",
	"CreationTime",
	"VolumeStartTime",
	"VolumeStopTime",
}

func initIden() map[string][]byte {
	return map[string][]byte{
		idenKey[0]: make([]byte, 4),
		idenKey[1]: make([]byte, 4),
		idenKey[2]: make([]byte, 2),
		idenKey[3]: make([]byte, 2),
		idenKey[4]: make([]byte, 12),
		idenKey[5]: make([]byte, 12),
		idenKey[6]: make([]byte, 12),
	}
}

// siteInfoKey for siteInfo header
var siteInfoKey = []string{
	"WMOCountryCode",
	"WMOSiteNumber",
	"RadarSiteLon",
	"RadarSiteLat",
	"LocalSiteNum",
	"LocalGridEasting",
	"LocalGridNorthing",
	"SensorHeight",
}

func initSiteInfo() map[string][]byte {
	return map[string][]byte{
		siteInfoKey[0]: make([]byte, 2),
		siteInfoKey[1]: make([]byte, 2),
		siteInfoKey[2]: make([]byte, 6),
		siteInfoKey[3]: make([]byte, 6),
		siteInfoKey[4]: make([]byte, 2),
		siteInfoKey[5]: make([]byte, 2),
		siteInfoKey[6]: make([]byte, 2),
		siteInfoKey[7]: make([]byte, 2),
	}
}

// hardwareConfKey for hardwareConf header
var hardwareConfKey = []string{
	"HardwareType",
	"SoftwareType",
	"ChannelNum",
	"Unused1",
	"Channel1PolarMode",
	"Channel2PolarMode",
	"Channel1RadarConstant",
	"Channel2RadarConstant",
	"Channel1Wavelength",
	"Channel2Wavelength",
	"Channel1BeamWidth",
	"Channel2BeamWidth",
	"Unused2",
}

func initHardwareConf() map[string][]byte {
	return map[string][]byte{
		hardwareConfKey[0]:  make([]byte, 2),
		hardwareConfKey[1]:  make([]byte, 2),
		hardwareConfKey[2]:  make([]byte, 2),
		hardwareConfKey[3]:  make([]byte, 2),
		hardwareConfKey[4]:  make([]byte, 2),
		hardwareConfKey[5]:  make([]byte, 2),
		hardwareConfKey[6]:  make([]byte, 2),
		hardwareConfKey[7]:  make([]byte, 2),
		hardwareConfKey[8]:  make([]byte, 2),
		hardwareConfKey[9]:  make([]byte, 2),
		hardwareConfKey[10]: make([]byte, 2),
		hardwareConfKey[11]: make([]byte, 2),
		hardwareConfKey[12]: make([]byte, 12),
	}
}

// processorConfKey for processorConf header
var processorConfKey = []string{
	"ScanType",
	"ScansNum",
	"RaysNum",
	"BinsNum",
	"BinLength",
	"PulseLength",
	"AntennaeRotationRate",
	"SamplesNum",
	"PrimaryPRF",
	"SecondaryPRF",
	"UnambigRange",
	"UnambigVelocity",
	"Unused",
}

func initProcessorConf() map[string][]byte {
	return map[string][]byte{
		processorConfKey[0]:  make([]byte, 2),
		processorConfKey[1]:  make([]byte, 2),
		processorConfKey[2]:  make([]byte, 2),
		processorConfKey[3]:  make([]byte, 2),
		processorConfKey[4]:  make([]byte, 2),
		processorConfKey[5]:  make([]byte, 2),
		processorConfKey[6]:  make([]byte, 2),
		processorConfKey[7]:  make([]byte, 2),
		processorConfKey[8]:  make([]byte, 2),
		processorConfKey[9]:  make([]byte, 2),
		processorConfKey[10]: make([]byte, 2),
		processorConfKey[11]: make([]byte, 2),
		processorConfKey[12]: make([]byte, 12),
	}
}

// dataProcessingKey for dataProcessing header
var dataProcessingKey = []string{
	"ProcessorFlags",
	"ClutterFilterType",
	"ClutterFilterResp",
	"ClutterPowerThrd",
	"NoiseThrd",
	"SQIThrd",
	"Allocated",
	"Unused",
}

func initDataProcessing() map[string][]byte {
	return map[string][]byte{
		dataProcessingKey[0]: make([]byte, 2),
		dataProcessingKey[1]: make([]byte, 2),
		dataProcessingKey[2]: make([]byte, 2),
		dataProcessingKey[3]: make([]byte, 2),
		dataProcessingKey[4]: make([]byte, 2),
		dataProcessingKey[5]: make([]byte, 2),
		dataProcessingKey[6]: make([]byte, 2),
		dataProcessingKey[7]: make([]byte, 10),
	}
}

// dataStorgeKey for dataStorge header
var dataStorgeKey = []string{
	"DerivedDataType",
	"SourceDataType",
	"ElementBytesNum",
	"ElementValuesNum",
	"Compression",
	"Allocated1",
	"Allocated2",
	"Unused",
}

func initDataStorge() map[string][]byte {
	return map[string][]byte{
		dataStorgeKey[0]: make([]byte, 2),
		dataStorgeKey[1]: make([]byte, 2),
		dataStorgeKey[2]: make([]byte, 2),
		dataStorgeKey[3]: make([]byte, 2),
		dataStorgeKey[4]: make([]byte, 2),
		dataStorgeKey[5]: make([]byte, 2),
		dataStorgeKey[6]: make([]byte, 2),
		dataStorgeKey[7]: make([]byte, 10),
	}
}

// diagnosticsKey for diagnostics header
var diagnosticsKey = []string{
	"DiagnosticFlags",
	"Unused",
}

func initDiagnostics() map[string][]byte {
	return map[string][]byte{
		diagnosticsKey[0]: make([]byte, 2),
		diagnosticsKey[1]: make([]byte, 62),
	}
}

// Volume contains the slice scans and the number of scans
type Volume struct {
	Header   map[string](map[string][]byte)
	Scans    []Scan
	ScansNum int16
}
